﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MMPS.Business;
using MMPS.Entity.ViewModel;
using MMPS.Common;

namespace MMPS.Controllers
{
    public class CardLevelsController : Controller
    {
        #region   调用BaseService中的CardLevesService会员等级方法显示列表数据
        /// <summary>
        /// 实例化Business中的CardLevelsService
        /// </summary>
        CardLevelsService GetCardLevel = new CardLevelsService();
        // GET: CardLevels
        public ActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 调用BaseService中的CardLevesService会员等级方法显示列表数据
        /// </summary>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        public ActionResult GetCardLevesInfo(CardLevelsGetViewModel viewModel)
        {
            var result = GetCardLevel.GetCardLeves(viewModel);
            return Json(result.Data);
        }
        #endregion

        #region  添加会员等级信息
        /// <summary>
        /// 添加  修改会员等级信息共用一个视图
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public ActionResult InsertCardLeves(int Id=0)
        {
            //判断  获取的Id是否大于0
            if (Id > 0)
            {
                //如若大于0  获取到要修改的信息的Id  并将获取到的数据放到变量result里
                var result = GetCardLevel.CardLevesEditById(Id);
                //判断result的结果状态是否为true 
                if (result.ResultStatus == ResultStatus.Success)
                {
                    //返回视图数据
                    return View(result.Data);
                }
                else
                {
                    //返回内容提示信息
                    return Content(result.Msg);
                }
            }
            else
            {
                //如果Id小于零则返回空的视图
                return View();
            }
        }
        [HttpPost]
        public ActionResult InsertCardLeves(CardLevelsViewModel viewModel)
        {
            //获取到添加会员等级信息的视图模型  将模型值赋给result
            var result = GetCardLevel.GetCardLevesInsert(viewModel);
            //返回Json格式
            return Json(result);
        }
        #endregion

        #region 修改会员等级信息
        [HttpPost]
        public ActionResult UpdateCardLevesList(CardLevelsViewModel viewModel)
        {
            //获取到修改会员等级信息的视图模型  将模型值赋给result
            var result = GetCardLevel.EditCardLevesList(viewModel);
            //返回Json格式
            return Json(result);
        }
        #endregion
        #region  删除所选中行的会员等级信息
        public ActionResult DeleteCardLeves(int Id)
        {
            //通过Id获取到所选中行的会员等级信息
            var result = GetCardLevel.DeleteCardLevesRows(Id);
            return Json(result);
        }
        #endregion
    }
}